package com.w2cx.selenium.business;

import com.w2cx.selenium.base.DriverBase;
import com.w2cx.selenium.operate.POI_CateManageOperate;
import org.openqa.selenium.WebElement;

import java.util.List;

public class POI_CateManageProcess {

    DriverBase driver;
    POI_CateManageOperate pcmh;
    public POI_CateManageProcess(DriverBase driver){
        this.driver = driver;
        pcmh = new POI_CateManageOperate(driver);
    }


    //添加poi分类
    public void addPoiCategory(String poiName){

        //点击基础数据管理
        pcmh.clickBaseDataManageMenu();
        //点击POI分类管理
        pcmh.clickPoiCateManageMenu();
        //点击添加
        pcmh.clickPoiAddBtn();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //输入名称
        pcmh.inputPoiName(poiName);
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //点击保存
        pcmh.clickPoiAddSave();
    }

    //判断添加是否成功
    public boolean addPoiCateSuccess(String poiName){
        //刷新列表
        driver.refresh();

        List<WebElement> list = pcmh.getPoiCateList();
        for (WebElement element:list){
            if(element.getText().contains(poiName)){
                return true;
            }
        }

        return false;
    }

    //删除poi
    public void delPoiCategory(String alreadyAddPoiName){
        //刷新列表
        driver.refresh();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        //点击删除按钮
        pcmh.clickPoiDelBtn(alreadyAddPoiName);
        //点击确定按钮
        pcmh.clickPoiDelConfirmBtn();
    }

    //判断删除是否成功
    public boolean delPoiSuccess(String alreadyAddPoiName){

        //刷新列表
        driver.refresh();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        List<WebElement> list = pcmh.getPoiCateList();
        for (WebElement element:list){
            if (element.getText().contains(alreadyAddPoiName)){
                return false;
            }
        }
        return true;
    }


}
